package cn.youqu.happy.module.youqu.dal.mysql.userAssess;

import cn.youqu.happy.framework.common.pojo.PageResult;
import cn.youqu.happy.framework.mybatis.core.mapper.BaseMapperX;
import cn.youqu.happy.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.youqu.happy.module.youqu.controller.admin.userAssess.vo.UserAssessExportReqVO;
import cn.youqu.happy.module.youqu.controller.admin.userAssess.vo.UserAssessPageReqVO;
import cn.youqu.happy.module.youqu.dal.dataobject.userAssess.UserAssessDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 用户评价 Mapper
 *
 * @author 王其岩 20112001045
 */
@Mapper
public interface UserAssessMapper extends BaseMapperX<UserAssessDO> {
    UserAssessDO findByIdAndTargetIdAndUid(@Param("id") Integer id, @Param("targetId") Long targetId, @Param("uid") Long uid);

    UserAssessDO findByIdAndUid(@Param("id") Integer id, @Param("uid") Long uid);

    List<UserAssessDO> findByActivityIdAndTargetIdAndUid(@Param("activityId") Integer activityId, @Param("targetId") Long targetId, @Param("uid") Long uid);

    UserAssessDO findOneByActivityIdAndTargetIdAndUid(@Param("activityId") Integer activityId, @Param("targetId") Long targetId, @Param("uid") Long uid);

    int updateNickNameByUid(@Param("updatedNickName") String updatedNickName, @Param("uid") Long uid);

    int updateAvatarByUid(@Param("updatedAvatar") String updatedAvatar, @Param("uid") Long uid);


    default PageResult<UserAssessDO> selectPage(UserAssessPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UserAssessDO>()
                .eqIfPresent(UserAssessDO::getUid, reqVO.getUid())
                .eqIfPresent(UserAssessDO::getAvatar, reqVO.getAvatar())
                .likeIfPresent(UserAssessDO::getNickName, reqVO.getNickName())
                .eqIfPresent(UserAssessDO::getStar, reqVO.getStar())
                .eqIfPresent(UserAssessDO::getComment, reqVO.getComment())
                .eqIfPresent(UserAssessDO::getImg, reqVO.getImg())
                .eqIfPresent(UserAssessDO::getReplayId, reqVO.getReplayId())
                .betweenIfPresent(UserAssessDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserAssessDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserAssessDO::getId));
    }

    default List<UserAssessDO> selectList(UserAssessExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<UserAssessDO>()
                .eqIfPresent(UserAssessDO::getUid, reqVO.getUid())
                .eqIfPresent(UserAssessDO::getAvatar, reqVO.getAvatar())
                .likeIfPresent(UserAssessDO::getNickName, reqVO.getNickName())
                .eqIfPresent(UserAssessDO::getStar, reqVO.getStar())
                .eqIfPresent(UserAssessDO::getComment, reqVO.getComment())
                .eqIfPresent(UserAssessDO::getImg, reqVO.getImg())
                .eqIfPresent(UserAssessDO::getReplayId, reqVO.getReplayId())
                .betweenIfPresent(UserAssessDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserAssessDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserAssessDO::getId));
    }

}
